import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:juming_test/model/domain/domain_filter_section_model.dart';

class DomainFilterMainList extends StatelessWidget {
  const DomainFilterMainList({
    super.key,
    required this.sections,
    required this.selectedIndex,
    required this.onSelectedIndexChanged,
  });

  // 域名筛选列表
  final List<DomainFilterSectionModel> sections;
  // 选中的 index
  final int selectedIndex;
  // 事件
  // 选中index
  final Function(int) onSelectedIndexChanged;

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemCount: sections.length,
      itemBuilder: (context, index) {
        final section = sections[index];
        return InkWell(
          onTap: () {
            onSelectedIndexChanged(index); // 更新选中的 index
          },
          child: Container(
            padding: const EdgeInsets.all(12),
            alignment: Alignment.center,
            color:
                selectedIndex == index
                    ? Colors.grey[200]
                    : Colors.white, // 选中的 section 高亮显示
            child: Row(
              children: [
                Container(
                  width: 5.w,
                  height: 5.w,
                  decoration: BoxDecoration(
                    color:
                        section.hasCondition
                            ? Colors.red[400]
                            : Colors.transparent, // 圆点颜色
                    shape: BoxShape.circle,
                  ),
                ),
                SizedBox(width: 5.w),
                Text(section.title),
              ],
            ),
          ),
        );
      },
    );
  }
}
